public class Test40 {
    public static int[] findNumbersAppearanceOnce(int[] data){
        int[] res = {0,0};
        if (data == null ||data.length < 2) return res;

        int xor = 0;
        //把data数组里面的是进行异或
        for (int i : data){
            xor ^= i;
        }
        //找到位置n
        int index = findFirstBit1(xor);
        for (int i : data){
            if (isBit1(i,index)){//如果在第一个分组中，把全部的进行异或，得到唯一的数
                res[0] ^= i;
            }else res[1] ^=i;//如果在第二个分组中，
        }
        return res;
    }

    public static int findFirstBit1(int num){
        int index = 0;
        //一共三十二位
        while((num & 1) == 0 && index < 32){
            num >>>=1;//无符号右移一位
            index ++;
        }
        return index;
    }

    public static  boolean isBit1(int num, int indexBit){
        num >>>= indexBit;
        return (num & 1) == 1;
    }

    public static void main(String[] args) {
        int[] data1 = {2, 4, 3, 6, 3, 2, 5, 5};
        int[] result1 = findNumbersAppearanceOnce(data1);
        System.out.println(result1[0] + " " + result1[1]);

        int[] data3 = {4, 6, 1, 1, 1, 1};
        int[] result3 = findNumbersAppearanceOnce(data3);
        System.out.println(result3[0] + " " + result3[1]);

    }
}
